package in.muton.edushare.newentities.upgraded;

import java.util.List;

import com.edushare.common.dao.UsersDAO;
import com.edushare.common.orm.ORMInterface;
import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.Enrolments;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.UserDeptLink;
import com.edushare.common.vo.UserRoles;
import com.edushare.common.vo.Users;

public class InviteUtils {
	public static boolean isUnivSubscriber(Universities univ, Users user) {
		List<UserRoles> roleList = user.getRoleList();
		for (UserRoles role : roleList) {
			if (univ == role.getUniversity()) {
				return true;
			}
		}
		return false;
	}

	public static Users getUserByString(String emailorid,
			ORMInterface ormInterface) {
		Users userVO = new UsersDAO(ormInterface)
				.getUserByUserNameOrEmail(emailorid);
		return userVO;
	}
	
	public static boolean isEmailId(String id) {
		if(!StringUtil.isValid(id))
			return false;
		
		try {
			new javax.mail.internet.InternetAddress(id, true);
		} catch (javax.mail.internet.AddressException e) {
			return false;
		}
		return true;
	}
	
	public static int getMatchingUnivRole(int role) {
		switch (role) {
		case (UserDeptLink.PRIMARY_ADMIN):
			return UserRoles.TEACHER_ROLE;
		case (UserDeptLink.TEACHER):
			return UserRoles.TEACHER_ROLE;
		case (UserDeptLink.STUDENT):
			return UserRoles.STUDENT_ROLE;
		}
		return 0;
	}
	
	public static int convertCourseRoleToDept(int role){
		switch(role){
		case Enrolments.TEACHER:
			return UserDeptLink.TEACHER;
		case Enrolments.STUDENT:
		case Enrolments.TEACHING_ASSISTANT:
		case Enrolments.OBSERVER:
			return UserDeptLink.STUDENT;
		}
		return 0;
	}
}
